package com.game.autoTool.project.web.utils;

import org.apache.http.conn.ssl.NoopHostnameVerifier;
import org.apache.http.conn.ssl.TrustAllStrategy;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.ssl.SSLContextBuilder;

import javax.net.ssl.SSLContext;
import java.security.KeyManagementException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;

public class HttpClientUtils {
    public static CloseableHttpClient createHttpClientWithDisabledSSLCheck() {
        try {
            SSLContext sslContext = SSLContextBuilder
                   .create()
                   .loadTrustMaterial(null, TrustAllStrategy.INSTANCE)
                   .build();

            return HttpClients.custom()
                   .setSSLContext(sslContext)
                   .setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE)
                   .build();
        } catch (NoSuchAlgorithmException | KeyManagementException | KeyStoreException e) {
            e.printStackTrace();
            return null;
        }
    }
}